package com.huluobo.a2201mvvm_imdemo.addGroup;

import androidx.lifecycle.MutableLiveData;

import com.huluobo.a2201mvvm_imdemo.mvvm.BaseViewModel;
import com.hyphenate.chat.EMGroup;
import com.hyphenate.chat.EMGroupInfo;
import com.hyphenate.chat.EMGroupOptions;

import java.util.List;

/**
 * Created by LC on 2024/3/28.
 */
public class AddGroupViewModel extends BaseViewModel<AddGroupRepo> {
    MutableLiveData<String> createGroupSuccess = new MutableLiveData<>();
    MutableLiveData<String> createGroupFailed = new MutableLiveData<>();
    MutableLiveData<List<EMGroupInfo>> getGroupsSuccess = new MutableLiveData<>();
    MutableLiveData<String> getGroupsFailed = new MutableLiveData<>();
    MutableLiveData<String> joinGroupSuccess = new MutableLiveData<>();
    MutableLiveData<String> joinGroupFaild = new MutableLiveData<>();
    MutableLiveData<List<EMGroup>> findJoinedGroupSuccess = new MutableLiveData<>();
    MutableLiveData<String> findJoinedGroupFailed = new MutableLiveData<>();

    public void findJoinedGroup() {
        repo.findJoinedGroup(findJoinedGroupSuccess, findJoinedGroupFailed);
    }

    public void joinGroup(String groupId) {
        repo.joinGroup(groupId, joinGroupSuccess, joinGroupFaild);
    }

    public void getGroups(int pageSize, String cursor) {
        repo.findPublicGroups(pageSize, cursor, getGroupsSuccess, getGroupsFailed);
    }

    public void createGroup(String groupName,//群的名字
                            String desc,//群的描述
                            String[] allMembers,//创建群的人员
                            String reason,//邀请群加入的申请
                            EMGroupOptions option//群设置:一定要传){
    ) {
        repo.createCroup(groupName, desc, allMembers, reason, option, createGroupSuccess, createGroupFailed);
    }


    @Override
    protected AddGroupRepo createRepo() {
        return new AddGroupRepo();
    }
}
